<template>
  <div class="">
    <SearchContainer @search="getData" @reset="() => formRef.resetFields()">
      <a-form ref="formRef" class="flex-1 form-style-flex" :model="formState" :label-col="{ style: { width: '80px' } }">
        <a-form-item name="mc">
          <a-input v-model:value="formState.mc" class="w-64" placeholder="医嘱项目/服务项目/助记码" />
        </a-form-item>
      </a-form>
    </SearchContainer>
    <a-card class="mt-2">
      <BaseTable
        :data-source="tableData"
        fill
        :expanded-row-keys="expandedRowKeys"
        :loading="loading"
        column-code="00001139"
        :pagination="pagination"
        @expand="onShowDetail"
      >
        <template #bodyCell="{ column, index, record }">
          <template v-if="column.dataIndex === 'xh'">
            {{ index + 1 }}
          </template>
          <template v-if="column.dataIndex === 'dj'">
            {{ record.dj.toFixed(3) }}
          </template>
          <template v-else-if="column.dataIndex === 'bh'">
            <PopoverTable :config="detailConfig" :params="{ sfxmbBh: record.bh }">{{ record.bh }}</PopoverTable>
          </template>
          <template v-if="column.dataIndex === 'action'">
            <a-space>
              <BaseButton type="link" size="small" :disabled="record.status === '1'" @click="onCLickControl(record)"> 服务项目对照 </BaseButton>
            </a-space>
          </template>
        </template>
      </BaseTable>
    </a-card>
  </div>
</template>

<script setup>
import { onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import SearchContainer from '@/components/SearchContainer'
// import dayjs from 'dayjs'
import BaseTable from '@/components/BaseTable'
// import { message } from 'ant-design-vue'

const router = useRouter()
const rowData = ref({})
const formState = ref({
  mc: ''
})

const detailConfig = ref({
  url: '/course/serviceItemAssociation/getServiceItemAssociation',
  columnCode: '00001140',
  rowKey: 'id',
  formatResult: (data) => {
    return data.map((item, index) => ({
      ...item,
      xh: index + 1
    }))
  }
})

const { loading, tableData, getData, pagination } = useTable({
  url: '/course/serviceItemAssociation/getClinicalDictInfoList',
  immediate: true,
  params: formState.value
})

const onCLickControl = async (record) => {
  rowData.value = record
  router.push({
    path: '/physiotherapy/manage/maintenance-detail',
    query: {
      mc: record.mc,
      bh: record.bh
    }
  })
  getData()
}
onMounted(() => {
  getData()
})
</script>
